<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>杂类问题</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="faq.migration5.html">从 PHP 4 移植到 PHP 5</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="appendices.html">附录</a></div>
 <div class="up"><a href="faq.html">FAQ</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="faq.misc" class="chapter">
  <h1>杂类问题</h1>

  
  <p class="para">有些问题没法归到其它类中，可以在这里找到。</p>
  <div class="qandaset"><ol class="qandaset_questions"><li><a href="#faq.misc.bz2">
        在 Windows 中怎样处理 bz2 压缩的文档？
      </a></li><li><a href="#faq.misc.arguments.references">
        在函数定义中，参数旁边的 &amp; 是什么意思？例如 
        asort。
      </a></li><li><a href="#faq.misc.registerglobals">
        怎么处理 
        register_globals？
      </a></li></ol></div>
    <dl class="qandaentry" id="faq.misc.bz2">
      <dt><strong>
        在 Windows 中怎样处理 bz2 压缩的文档？
      </strong></dt>
      <dd class="answer">
        <p class="para">如果没有能处理 bz2 文件的压缩工具，从 Redhat 
        <a href="http://www.bzip.org/" class="link external">&raquo;&nbsp;下载</a>一个命令行工具（进一步信息见下面）。</p>
        <p class="para">如果不喜欢用命令行工具，可以试试免费工具例如 
        <a href="http://www.stuffit.com/" class="link external">&raquo;&nbsp;Stuffit Expander</a>，
        <a href="http://www.ultimatezip.com/" class="link external">&raquo;&nbsp;UltimateZip</a>，
        <a href="http://www.7-zip.org/" class="link external">&raquo;&nbsp;7-Zip</a>或者 
        <a href="http://www.quickzip.org/" class="link external">&raquo;&nbsp;Quick Zip</a>。如果有像 
        <a href="http://www.rarlab.com/" class="link external">&raquo;&nbsp;WinRAR</a>或者 
        <a href="http://www.powerarchiver.com/" class="link external">&raquo;&nbsp;Power Archiver</a>之类的工具，可以很容易用它解压缩 bz2 文件。如果用 Total Commander（前身为 Windows Commander），可以从 
        <a href="http://www.ghisler.com/" class="link external">&raquo;&nbsp;Total Commander</a>网站免费得到一个 bz2 插件。</p>
        <p class="para">来自 Redhat 的 bzip2 命令行工具：</p>
        <p class="para">Win2K Sp2 用户下载最新版本 1.0.2，所有其它 Windows 用户应该用版本 1.00。下载后重命名可执行文件为 bzip2.exe。为方便起见将其放到一个在你路径中的目录，例如 C:\Windows，C 表示你安装 Windows 的盘符。</p>
        <p class="para">注意：lang 指的是你的语种，x 是想要的格式，例如：pdf。要解压缩 php_manual_lang.x.bz2，按照下面的简单说明进行： 
        <ul class="itemizedlist">
          <li class="listitem">
            <span class="simpara">打开一个命令行窗口</span>
          </li>
          <li class="listitem">
            <span class="simpara">进入存放已下载的 php_manual_lang.x.bz2 的目录</span>
          </li>
          <li class="listitem">
            <span class="simpara">调用 bzip2 -d php_manual_lang.x.bz2，将 php_manual_lang.x 释放到同一个目录</span>
          </li>
        </ul></p>
        <p class="para">在下载了包含很多 html 文件的 php_manual_lang.tar.bz2 的情况下，过程是一样的。唯一区别是得到了一个 php_manual_lang.tar 文件。tar 格式可以被大多数 Windows 下流行的压缩工具所处理，例如 
        <a href="http://www.winzip.com/" class="link external">&raquo;&nbsp;WinZip</a>。</p>
      </dd>
    </dl>
    <dl class="qandaentry" id="faq.misc.arguments.references">
      <dt><strong>
        在函数定义中，参数旁边的 &amp; 是什么意思？例如 
        <span class="function"><a href="function.asort.html" class="function">asort()</a></span>。
      </strong></dt>
      <dd class="answer">
        <p class="para">这表示该参数是
        <a href="language.references.pass.html" class="link">引用传递</a>，该函数会修改其值。只可以用此方法传递变量，其实都不需要在函数调用中用 &amp; 传递（此方式都已
        <a href="ini.core.html#ini.allow-call-time-pass-reference" class="link">过时了</a>）。</p>
      </dd>
    </dl>
    <dl class="qandaentry" id="faq.misc.registerglobals">
      <dt><strong>
        怎么处理 
        <em>register_globals</em>？
      </strong></dt>
      <dd class="answer">
        <p class="para">有关 
        <em>register_globals</em>实现方面的安全性，请阅读
        <a href="security.globals.html" class="link">使用 register_globals</a>一章。</p>
        <p class="para">推荐使用
        <a href="language.variables.superglobals.html" class="link">超全局变量</a>而不要依赖 
        <em>register_globals</em>。</p>
        <p class="para">如果需要在一台关闭了 
        <em>register_globals</em>的共享主机上运行一些旧式程序而该程序需要此选项打开时，或者在一些打开了此选项的主机上但想消除安全隐患，那么就需要用 PHP 来模拟出相反的设定。最好先问清楚是否能否在哪里更改 PHP 配置的选项，如果不行，那可以用如下的兼容手段。</p>
        <p class="para">
          <div class="example" id="example-5487">
            <p><strong>Example #1 模拟注册全局变量</strong></p>
            <div class="example-contents"><p>本例模拟 register_globals On。如果改变了配置文件中的 
            <a href="ini.core.html#ini.variables-order" class="link">variables_order</a>选项，则考虑对 
            <var class="varname"><var class="varname">$superglobals</var></var>作出相应的改动。</p></div>
            <div class="example-contents">
              <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Emulate&nbsp;register_globals&nbsp;on<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'register_globals'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$superglobals&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_ENV</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isset(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_unshift</span><span style="color: #007700">(</span><span style="color: #0000BB">$superglobals</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$superglobals&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$superglobal</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #0000BB">$superglobal</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">EXTR_SKIP</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
</div>

            <div class="example-contents"><p>本例模拟 register_globals Off。要记住此代码应在脚本最开头的地方调用。如果使用了会话机制，则在 
            <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span>之后调用。</p></div>
            <div class="example-contents">
              <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Emulate&nbsp;register_globals&nbsp;off<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">unregister_GLOBALS</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'register_globals'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Might&nbsp;want&nbsp;to&nbsp;change&nbsp;this&nbsp;perhaps&nbsp;to&nbsp;a&nbsp;nicer&nbsp;error<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(isset(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">])&nbsp;||&nbsp;isset(</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">[</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">]))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'GLOBALS&nbsp;overwrite&nbsp;attempt&nbsp;detected'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Variables&nbsp;that&nbsp;shouldn't&nbsp;be&nbsp;unset<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$noUnset&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'GLOBALS'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'_GET'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'_POST'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'_COOKIE'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'_REQUEST'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'_SERVER'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'_ENV'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'_FILES'</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$input&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_merge</span><span style="color: #007700">(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_ENV</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isset(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">)&nbsp;&amp;&amp;&nbsp;</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #0000BB">$_SESSION&nbsp;</span><span style="color: #007700">:&nbsp;array());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$input&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$k&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$v</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">in_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$k</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$noUnset</span><span style="color: #007700">)&nbsp;&amp;&amp;&nbsp;isset(</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #0000BB">$k</span><span style="color: #007700">]))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset(</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #0000BB">$k</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">unregister_GLOBALS</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
</div>

          </div>
        </p>
      </dd>
    </dl>
  
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="faq.migration5.html">从 PHP 4 移植到 PHP 5</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="appendices.html">附录</a></div>
 <div class="up"><a href="faq.html">FAQ</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
